package com.hzcx.app.simplechat.ui.setting.adapter;

import android.widget.CompoundButton;
import android.widget.Switch;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.ui.setting.bean.VipSettingBean;

import java.util.List;

public class VipSettingAdapter extends BaseQuickAdapter<VipSettingBean, BaseViewHolder> {

    private OnSwitchChangeListener listener;

    public VipSettingAdapter(@Nullable List<VipSettingBean> data) {
        super(R.layout.rv_item_vip_setting, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, VipSettingBean item) {
        helper.setText(R.id.tv_content, item.getName());
        Switch switchBtn = helper.getView(R.id.switch_btn);
        switchBtn.setChecked(item.getList().getSate() == 1 ? true : false);

        switchBtn.setOnCheckedChangeListener((compoundButton, b) -> {
            if (listener != null) {
                listener.change(helper.getAdapterPosition(), b);
            }
        });
    }

    public interface OnSwitchChangeListener {
        void change(int pos, boolean isChecked);
    }

    public void setOnSwitchChangeListener(OnSwitchChangeListener listener) {
        this.listener = listener;
    }
}
